package service.impl;

import static org.junit.Assert.*;

import java.util.List;

import model.Film;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.transaction.annotation.Transactional;

/**
 * Intergration test showing the basic usage of {@link FilmRepository}.
 * 
 * @author Andre
 */
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "classpath:repository-context.xml")
@Transactional
public class FilmRepositorySample {

	@Autowired
	FilmRepository repository;

	/**
	 * Tests inserting a film and asserts it can be loaded again.
	 */
	@Test
	public void testInsert() {

		Film film = new Film("Film");
		film.setName("Film");
		film.setHauptdarsteller("Hauptdarsteller");
		film.setGenre("Genre");
		film.setLaenge(110);

		film = repository.save(film);

		assertEquals(film, repository.findOne(film.getId()));
	}

	@Test
	public void film() {

		Film film = new Film("Film");
		film.setName("Film");
		film.setHauptdarsteller("Hauptdarsteller");
		film.setGenre("Genre");
		film.setLaenge(110);

		film = repository.save(film);

		List<Film> films = repository.findByName("Film");

		assertNotNull(films);
		assertTrue(films.contains(film));

	}

	// /**
	// * Test invocation of film method.
	// */
	// @Test
	// public void testDatentraegerMethod() {
	//
	// Film film = new Film("Film");
	// film.setName("Film");
	// film.setHauptdarsteller("Hauptdarsteller");
	// film.setGenre("Genre");
	// film.setLaenge(110);
	//
	// film = repository.save(film);
	//
	// List<Film> films = repository.datentraegerBatchOperation();
	//
	// assertNotNull(films);
	// assertTrue(films.contains(film));
	// }
}
